package com.liu.kafka.controller;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * @author liuxinghong
 * @Description: 项目启动后  执行该方法
 * @date 2019/6/20 002011:46
 */
@Component
public class KafkaTestComponent implements ApplicationListener<ContextRefreshedEvent> {



    @Autowired
    private  KafkaProducer kafkaProducer;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        for (int i= 1; i<1000; i++){
            kafkaProducer.send("第 "+i+"条消息，发送消息开始了+"+ DateTime.now().toString());
        }
    }
}
